package com.qf.service.impl;

import com.qf.dao.LoginDao;
import com.qf.entity.Privilege;
import com.qf.entity.User;
import com.qf.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private LoginDao dao;
    //根据提供的用户名拿密码
    @Override
    public User getPasswordByUserId(String userId) {
        return dao.findUserByUserId(userId);
    }

    //修改某一用户的密码
    @Override
    public void modifyPasswordByUserId(String userId, String newpassword) {
        User user = dao.findUserByUserId(userId);
        user.setUserId(userId);
        user.setPassword(newpassword);
        dao.modifyPasswordByUserId(user);
    }

    @Override
    public List<Privilege> findPrivileges(int roleId) {
        if (!dao.findPrivileges(roleId).isEmpty()) {
            return dao.findPrivileges(roleId);
        }
        return null;
    }
}
